var app = getApp();
var api = require('../../../utils/api.js')
Page({
  updateList: true,
  data: {
    
  },
  onShow: function () {
    var that = this
    app.registerPage(that)
    wx.request({
      url: api.audioList + "?albumid=" + that.data.options.pid + "&page=-1&row=-1",
      success: function (res) {
        that.setData({
          list: res.data.dataList,
          cover: res.data.dataImg,
          albumInfo: {
            count: res.data.count,
            title: res.data.dataTitle,
            support: res.data.dataSupport,
            date: res.data.dataDate,
          },
        })
        wx.setNavigationBarTitle({
          title: res.data.dataTitle
        })
      }, fail: function (res) {
        wx.navigateBack({
          delta: 1
        })
      }
    })
    that.setData({
      music: app.globalData.music,
      idx: app.globalData.index,
    })
    that.updatePlayInfo()
  },
  onHide: function () {
    
  },
  onUnload: function(){
    
  },
  onLoad: function (options) {
    var that = this
    that.setData({
      options: options
    })
  },
  playAll: function(){
    var that = this
    app.globalData.list = that.data.list
    app.play(() => {
      that.setData({
        music: app.globalData.music
      })
    }, 0)
  },
  toggleMusic: function (e) {
    var that = this
    app.toggleMusic(() => {
      that.setData({
        music: app.globalData.music
      })
    }, e.currentTarget.dataset.shift, e.currentTarget.dataset.trigger)
  },
  updatePlayInfo: function(){
    var that = this
    var playInfo = app.getPlayInfo()
    that.setData({
      playing: !playInfo.paused
    })
  },
  contiune: function () {
    var that = this
    app.seek(() => {}, -1)
  },
  pause: function () {
    var that = this
    app.pause(() => {})
  },
  updateAppList: function(){
    var that = this
    app.globalData.list = that.data.list
  }
});